<?php namespace Home\Controller;

use Hdphp\Controller\Controller;

class ListController extends Controller{
	
	private $cateModel;
	
	public function __construct(){
		parent::__construct();
		$this->cateModel = new \Common\Model\Cate; 
	}
	
	
	public function index(){
		//获得分类数据 显示在列表页左侧
		$cateData = $this->cateModel->where("pid = 0")->get();
		$data = array();
		foreach ($cateData as $k => $v) {
			foreach ($this->cateModel->where("pid={$v['cid']}")->get() as $key => $value) {
				$data [] = $value;
			}
		}
		foreach ($data as $k => $v) {
			$data[$k]['son'] = $this->cateModel->where("pid={$v['cid']}")->get();
		}
		View::with('catedata',$data);
		//获得传过来的cid
		if(Q('get.cid',0,'intval')){
			$cid = Q('get.cid',0,'intval');
			$cidson = $this->cateModel->getSon($this->cateModel->get(),$cid);
			$cidson [] = $cid;
			$cidstr = implode(',', $cidson);
			$sql = "category_cid IN (".$cidstr.")";
			$goodsData = Db::table('goods')->where($sql)->get();
//			sp($goodsData);
			foreach ($goodsData as $k => $v) {
				$goodsData[$k]['brand_name'] = Db::table('brand')
												->where("bid={$v['brand_bid']}")
												->pluck('bname');
			}
		}
		if(Q('get.sid',0,'intval')){
			$goodsData = Db::table('goods')->where("sale_status=2")->get();
			foreach ($goodsData as $k => $v) {
				$goodsData[$k]['brand_name'] = Db::table('brand')
												->where("bid={$v['brand_bid']}")
												->pluck('bname');
			}
		}
		View::with('goodsData',$goodsData);
		View::make();
	}
	
	
}

 ?>